﻿package  com.hadron.mp3player
{
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.text.TextField;
	import flash.text.TextFieldAutoSize;
	
	/**
	 * ...
	 * @author Hadron
	 */
	public class TrackTimer extends Sprite
	{
		
		private var _length:Number;
		public function set length(value:Number):void
		{
			if (value != 0)
			{
				_length = value;
			}
		}
		
		public function get length():Number
		{
			return _length;
		}
		
		private var _position:Number;
		public function set position(value:Number):void
		{
			if (value != 0)
			{
				_position = value;
			}
		}
		
		public function get position():Number
		{
			return _position;
		}
		
		private var tf:TextField;
		
		public function TrackTimer(len:Number = 0, pos:Number = 0) 
		{
			this.length = len;
			this.position = pos;
			tf = new TextField();
			tf.defaultTextFormat = new TrackTextFormat();
			tf.autoSize = TextFieldAutoSize.RIGHT;
			addChild(tf);
		}
		
		public function validateNow():void
		{
			addEventListener(Event.ENTER_FRAME, onEnterFrame, false, 0, true);
		}
		
		private var minutes:Number;
		private var seconds:Number;
		private function onEnterFrame(e:Event):void
		{
			minutes = Math.floor(position / 1000 / 60);
			seconds = Math.floor(position / 1000) % 60;
			tf.text = '( ' + minutes + " : " + seconds + ' )';
		}
		
	}
	
}